package com.collection.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

@Entity
public class ContentStrategy implements Serializable {
	
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	
	private String charCode;
	@OneToMany(targetEntity = BaseStrategy.class, cascade = CascadeType.ALL)
    @JoinColumn(name="contentStrategy_id",referencedColumnName="id")
	private List<BaseStrategy> baseStrategies;
	
	@OneToOne(cascade=CascadeType.ALL)
	@JoinColumn(name="collectionTask_id")
	private CollectionTask collectionTask;
	
	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}
	
	public String getCharCode() {
		return charCode;
	}

	public void setCharCode(String charCode) {
		this.charCode = charCode;
	}

	public List<BaseStrategy> getBaseStrategies() {
		return baseStrategies;
	}

	public void setBaseStrategies(List<BaseStrategy> baseStrategies) {
		this.baseStrategies = baseStrategies;
	}
	
	public CollectionTask getCollectionTask() {
		return collectionTask;
	}

	public void setCollectionTask(CollectionTask collectionTask) {
		this.collectionTask = collectionTask;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj != null && (obj instanceof ContentStrategy)) {
			return ((ContentStrategy) obj).getId().equals(id);
		}
		return super.equals(obj);
	}

	@Override
	public int hashCode() {
		if (getId() == null) {
			return super.hashCode();
		} else {
			return this.getId().hashCode();
		}
	}
}
